package com.qubuyer.business.mine.adapter

import com.qubuyer.R
import com.qubuyer.business.mine.activity.MessageDetailActivity
import com.qubuyer.business.order.activity.OrderDetailActivity
import com.qubuyer.databinding.ItemMessageListBinding
import com.qubuyer.repository.entitys.MessageEntity
import com.qubuyer.repository.entitys.OrderEntity
import com.qubuyer.utils.NavigationUtil
import com.qubyer.widget.adapter.BindingRvAdapter

/**
 * @author Susong
 * @date 创建时间:2019/4/15
 * @description 消息列表adapter
 * & @version
 */
class MessageListAdapter(private val mType: Int) :
    BindingRvAdapter<MessageEntity, ItemMessageListBinding>() {

    override val itemLayout: Int
        get() = R.layout.item_message_list

    override fun onBind(data: MessageEntity, dataBinding: ItemMessageListBinding) {
        dataBinding.host = this
        dataBinding.data = data
    }

    fun onItemClick(data: MessageEntity) {
        if (mType == 1) {
            NavigationUtil.overlay(mContext, MessageDetailActivity::class.java, data.id)
        } else {
            val orderEntity = OrderEntity()
            orderEntity.order_id = data.master_id?.toInt() ?: 0
            orderEntity.id = data.order_id?.toInt() ?: 0
            NavigationUtil.overlay(mContext, OrderDetailActivity::class.java, orderEntity)
        }
    }
}